package com.dongfanggroup.report.service.impl;

import com.dongfanggroup.report.domain.ReportOrderHistory;
import com.dongfanggroup.report.enums.ReportOrderStatusEnum;
import com.dongfanggroup.report.mapper.ReportOrderHistoryMapper;
import com.dongfanggroup.report.service.IReportOrderHistoryService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 报障单历史Service业务层处理
 *
 * @author wangsr
 * @date 2021-12-16
 */
@Service
public class ReportOrderHistoryServiceImpl implements IReportOrderHistoryService {
    @Autowired
    private ReportOrderHistoryMapper reportOrderHistoryMapper;


    /**
     * 查询报障单历史
     *
     * @param id 报障单历史主键
     * @return 报障单历史
     */
    @Override
    public ReportOrderHistory selectReportOrderHistoryById(Long id) {
        return reportOrderHistoryMapper.selectReportOrderHistoryById(id);
    }

    /**
     * 查询报障单历史列表
     *
     * @param reportOrderHistory 报障单历史
     * @return 报障单历史
     */
    @Override
    public List<ReportOrderHistory> selectReportOrderHistoryList(ReportOrderHistory reportOrderHistory) {
        return reportOrderHistoryMapper.selectReportOrderHistoryList(reportOrderHistory);
    }

    /**
     * 新增报障单历史
     *
     * @param reportOrderHistory 报障单历史
     * @return 结果
     */
    @Override
    public int insertReportOrderHistory(ReportOrderHistory reportOrderHistory) {
        reportOrderHistory.setCreateTime(DateUtils.getNowDate());
        return reportOrderHistoryMapper.insertReportOrderHistory(reportOrderHistory);
    }

    /**
     * 修改报障单历史
     *
     * @param reportOrderHistory 报障单历史
     * @return 结果
     */
    @Override
    public int updateReportOrderHistory(ReportOrderHistory reportOrderHistory) {
        return reportOrderHistoryMapper.updateReportOrderHistory(reportOrderHistory);
    }

    /**
     * 批量删除报障单历史
     *
     * @param ids 需要删除的报障单历史主键
     * @return 结果
     */
    @Override
    public int deleteReportOrderHistoryByIds(Long[] ids) {
        return reportOrderHistoryMapper.deleteReportOrderHistoryByIds(ids);
    }

    /**
     * 删除报障单历史信息
     *
     * @param id 报障单历史主键
     * @return 结果
     */
    @Override
    public int deleteReportOrderHistoryById(Long id) {
        return reportOrderHistoryMapper.deleteReportOrderHistoryById(id);
    }

    @Override
    public List<ReportOrderHistory> selectReportOrderHistoryByReportId(Long reportId) {
        return reportOrderHistoryMapper.selectReportOrderHistoryByReportId(reportId);
    }

    @Override
    public void insertNewLog(Long reportId, String info, ReportOrderStatusEnum statusEnum) {
        ReportOrderHistory reportOrderHistory = new ReportOrderHistory();
        reportOrderHistory.setReportOrderId(reportId);
        reportOrderHistory.setReportStatus(statusEnum.getName());
        reportOrderHistory.setDealUserId(SecurityUtils.getUserId());
        reportOrderHistory.setCreateBy(SecurityUtils.getUserId().toString());
        reportOrderHistory.setCreateTime(DateUtils.getNowDate());
        reportOrderHistory.setReportInfo(info);
        insertReportOrderHistory(reportOrderHistory);
    }
}
